package org.szy.admin.controller;

import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Get;
import org.noear.solon.annotation.Mapping;
import org.noear.solon.core.handle.ModelAndView;
import org.szy.core.auth.util.SaLoginUtil;
import org.szy.core.auth.util.SaUtil;
import org.szy.core.common.controller.BaseController;
import org.szy.core.common.entity.LoginUser;

/**
 * 首页控制器
 *
 * @author 孙志阳
 * @date 2023-02-15
 * @since 1.0.0
 **/
@Controller
@Mapping
public class HomeController extends BaseController {

    private final String PATH_PREFIX = "/home/";

    @Get
    @Mapping()
    public ModelAndView home() {
        ModelAndView view = new ModelAndView(PATH_PREFIX + "index");
        LoginUser user = SaLoginUtil.getLoginUser();
        view.put("name", user.getName());
        view.put("avatar", user.getAvatar());
        return view;
    }

    @Get
    @Mapping("/home")
    public ModelAndView homeIndex() {
        ModelAndView view = new ModelAndView(PATH_PREFIX + "index");
        LoginUser user = SaLoginUtil.getLoginUser();
        view.put("name", user.getName());
        view.put("avatar", user.getAvatar());
        return view;
    }

    @Get
    @Mapping("/home/welcome")
    public ModelAndView welcome() {
        return new ModelAndView(PATH_PREFIX + "welcome");
    }


}
